package com.kotlin.flong.coroutines1

import kotlinx.coroutines.CoroutineName
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking

/**
 * @Author:liangjl
 * @Date: 2020/7/9-19:29
 * @Eamil:jilongliang@sina.com
 * @Description:
 * CoroutineName 上下文元素可以让我们对协程进行命名，以便能够输出可读性较好的日志信息
 * VM options --> -Dkotlinx.coroutines.debug
 */
private fun log(logMsg: String) = println("[${Thread.currentThread().name}] $logMsg")

fun main() = runBlocking(CoroutineName("main")) {
    log("hello")

    var value1 = async(CoroutineName("coroutine1")) {
        delay(800)
        log("coroutine1 log ")
        30
    }

    var value2 = async(CoroutineName("coroutine2")) {
        delay(1000)
        log("coroutine2 log ")
        5
    }

    println("result = ${value1.await() * value2.await()}")


}